package com.astrob.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;

import com.astrob.naviframe.Start;
import com.astrob.nhcmap.R;
import com.astrob.util.Utils;

import org.mapsforge.map.android.graphics.AndroidGraphicFactory;
import org.mapsforge.map.model.DisplayModel;

public class Compass {

    private final static int COMPASS_ID = R.drawable.compass00;
    private int mX = 3;
    private int mY = 51;

    public void setLeftTop(int left, int top) {
        mX = left;
        mY = top;
    }

    public void draw(Context context, Canvas canvas, float sx, float sy) {

        int dir = (int)Start.getInstance().MapKit().getRotation();
        // 指北针
        Bitmap bm = ((BitmapDrawable) context.getResources()
                .getDrawable(COMPASS_ID)).getBitmap();

        bm = Start.rotateBitmap(bm, -dir);

        //5, 53 dp
        int x = Utils.dip2px(context, mX);
        int y = Utils.dip2px(context, mY);

        canvas.drawBitmap(bm, x, y, null);
    }

    public void draw2(Context context, Canvas canvas, int dir) {
        // 指北针
        Bitmap bm = ((BitmapDrawable) context.getResources()
                .getDrawable(COMPASS_ID)).getBitmap();

        bm = Start.rotateBitmap(bm, -dir);

        //5, 53 dp
        int x = Utils.dip2px(context, mX);
        int y = Utils.dip2px(context, mY);

        canvas.drawBitmap(bm, x, y, null);
    }

    public void draw3(Context context, org.mapsforge.core.graphics.Canvas canvas, int dir, org.mapsforge.core.model.BoundingBox bb, byte zoomLevel, org.mapsforge.core.model.Point topLeftPoint, DisplayModel displayModel) {

        //Mapsforge 地图还不能旋转，一直指北
        android.graphics.Canvas androidCanvas = AndroidGraphicFactory.getCanvas(canvas);

        Bitmap bm = ((BitmapDrawable) context.getResources()
                .getDrawable(COMPASS_ID)).getBitmap();

        bm = Start.rotateBitmap(bm, -dir);

        //5, 53 dp
        int x = Utils.dip2px(context, mX);
        int y = Utils.dip2px(context, mY);

        androidCanvas.drawBitmap(bm, x, y, null);
    }

}
